Skip to content

Conversation

@DmySyz
Copy link
Contributor

@DmySyz DmySyz commented Nov 13, 2025

Description

Implements #8986 and #9035

This PR implements the feature to remember and restore the last selected account after the client restarts. Previously, the client would always select the first account on startup, which was frustrating for users with multiple accounts.

Changes Made

  1. ConfigFile (src/libsync/configfile.h and configfile.cpp):

    • Added lastSelectedAccountC constant for the settings key
    • Added lastSelectedAccount() getter method
    • Added setLastSelectedAccount() setter method
  2. UserModel (src/gui/tray/usermodel.cpp):

    • Modified buildUserList() to restore the last selected account on startup
    • Modified setCurrentUserId() to save the account id when user changes accounts
    • If the account written in the settings is unavailable - choses the first one (provided that it exists)

How It Works

  • On account selection: When a user manually selects an account, the selection is saved to nextcloud.cfg
  • On startup: buildUserList() attempts to restore the last selected account
  • Fallback: If the saved account doesn't exist or the id was corrupted, it falls back to the first account

Technical Details

  • Handles edge cases: deleted accounts, empty account lists, etc.

Testing

The fix has been manually tested. Unit test has not been added as an appropriate existing test for the relevant component was not found and creating it was deemed out of scope for this PR.

Screenshots

feat_preserve_acc.mp4

Notes

As account IDs are not randomly generated it is possible that a wrong account will be selected if somehow the original one was deleted and another one was created in its place outside the client.

@DmySyz
Copy link
Contributor Author

DmySyz commented Nov 13, 2025

Sorry, it seems I've borked my github setup (haven't used github in a long time).
Does someone know if it is possible to remove the merge commit with the github cli (gh)?

Copy link
Collaborator

@i2h3 i2h3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does someone know if it is possible to remove the merge commit with the github cli (gh)?

I do not know about gh but in Git it would be an git rebase --interactive on master in which the merge commit is just dropped then. 🤔

@DmySyz DmySyz force-pushed the preserve-selected-account-between-runs branch 3 times, most recently from 2e8a4db to 1de5dd4 Compare November 17, 2025 09:12
@DmySyz
Copy link
Contributor Author

DmySyz commented Nov 17, 2025

Does someone know if it is possible to remove the merge commit with the github cli (gh)?

I do not know about gh but in Git it would be an git rebase --interactive on master in which the merge commit is just dropped then. 🤔

Was overthinking it a bit 😅

@DmySyz
Copy link
Contributor Author

DmySyz commented Nov 17, 2025

@Aiiaiiio Seems you have been reviewing the previous attempt at implementing this thingy. Could you take a look at this one as well if you have some time?

@DmySyz DmySyz requested a review from i2h3 November 17, 2025 09:20
@mgallien mgallien force-pushed the preserve-selected-account-between-runs branch from 1de5dd4 to 70be1f0 Compare November 17, 2025 15:42
@DmySyz
Copy link
Contributor Author

DmySyz commented Nov 17, 2025

Not entirely sure what is wrong with the SonarCloud check. If someone could clarify whether the issue is on my side, I'd be grateful 👍

Copy link
Collaborator

@mgallien mgallien left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DmySyz can you solve the conflicts ?
sorry that you have to do it

@DmySyz DmySyz force-pushed the preserve-selected-account-between-runs branch from 6592632 to 70be1f0 Compare November 18, 2025 15:33
@DmySyz
Copy link
Contributor Author

DmySyz commented Nov 18, 2025

@DmySyz can you solve the conflicts ? sorry that you have to do it

No worries. Should be ok now

@DmySyz DmySyz requested a review from mgallien November 18, 2025 15:53
@DmySyz DmySyz force-pushed the preserve-selected-account-between-runs branch from 3b71687 to 70be1f0 Compare November 19, 2025 09:01
@mgallien mgallien enabled auto-merge November 19, 2025 09:03
Copy link
Collaborator

@Aiiaiiio Aiiaiiio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks awesome! See my change request please. We can discuss if you disagree.

@DmySyz DmySyz requested a review from Aiiaiiio November 19, 2025 09:57
@DmySyz
Copy link
Contributor Author

DmySyz commented Nov 19, 2025

Not entirely sure what is wrong with the SonarCloud check. If someone could clarify whether the issue is on my side, I'd be grateful 👍

Still broken unfortunately.

"Project not found. Please check the 'sonar.projectKey' and 'sonar.organization' properties, the 'SONAR_TOKEN' environment variable, or contact the project administrator to check the permissions of the user the token belongs to"

auto-merge was automatically disabled November 20, 2025 07:55

Head branch was pushed to by a user without write access

@DmySyz DmySyz force-pushed the preserve-selected-account-between-runs branch from 37b05a7 to 70be1f0 Compare November 20, 2025 07:55
@DmySyz DmySyz force-pushed the preserve-selected-account-between-runs branch from c5d7ce3 to 70be1f0 Compare November 20, 2025 14:50
@DmySyz DmySyz force-pushed the preserve-selected-account-between-runs branch 2 times, most recently from 70be1f0 to 5a2a9fb Compare November 21, 2025 06:35
@DmySyz
Copy link
Contributor Author

DmySyz commented Nov 21, 2025

@Aiiaiiio sorry for dragging this thing on, but I think this version is the cleanest solution for now.
Could you take a look one more time? 😄

@DmySyz DmySyz requested a review from Aiiaiiio November 21, 2025 06:44
Copy link
Collaborator

@Aiiaiiio Aiiaiiio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it! Thank you!

@DmySyz DmySyz force-pushed the preserve-selected-account-between-runs branch 3 times, most recently from 0dfabf9 to 5a2a9fb Compare November 22, 2025 14:24
Added an extra setting in the config that contains an account id to
  store the last one selected

Modified usermodel logic to auto select the account using the id from
  the config

Modified the account manager and user model to init user list after account
  restoration completes

Signed-off-by: Dmytro Syzov <[email protected]>
@DmySyz DmySyz force-pushed the preserve-selected-account-between-runs branch 3 times, most recently from 037fcf7 to fb9fd94 Compare November 24, 2025 11:44
@mgallien mgallien enabled auto-merge November 24, 2025 12:37
@mgallien mgallien added this to the 4.1.0 milestone Nov 24, 2025
@github-actions
Copy link

Artifact containing the AppImage: nextcloud-appimage-pr-9061.zip

Digest: sha256:2d88c86a3feccb1086a0387c14047dbdc965db8c0e5c06a281b81be8311e4b0c

To test this change/fix you can download the above artifact file, unzip it, and run it.

Please make sure to quit your existing Nextcloud app and backup your data.

@mgallien mgallien merged commit 80a3b86 into nextcloud:master Nov 24, 2025
18 of 19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants